package tree;

import java.util.ArrayList;

public class TreeErgodic {
    public static void main(String[] args) {
        Tree four = new Tree(4, null, null);
        Tree five = new Tree(5, null, null);
        Tree two = new Tree(2, four, five);
        Tree three = new Tree(3, null, null);
        Tree one = new Tree(1,two,three);
        System.out.println("先序");
        precedence(one);
        System.out.println();
        System.out.println("中序");
        inorder(one);
        System.out.println();
        System.out.println("后序");
        followUp(one);
    }
    public static void precedence(Tree tree){
        if(tree == null){
            return;
        }
        System.out.print(tree.getVal()+" ");
        precedence(tree.getLeft());
        precedence(tree.getRight());
    }
    public static void inorder(Tree tree){
        if(tree == null){
            return;
        }
        inorder(tree.getLeft());
        System.out.print(tree.getVal()+" ");
        inorder(tree.getRight());
    }
    public static void followUp(Tree tree){
        if(tree == null){
            return;
        }
        followUp(tree.getLeft());
        followUp(tree.getRight());
        System.out.print(tree.getVal()+" ");
    }
}
